package com.woniu.controller;

import com.woniu.entity.Result;
import com.woniu.pojo.MarkArticle;
import com.woniu.service.IMarkArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author doujiao
 * @since 2022-10-12
 */
@RestController
@RequestMapping("/markArticle")
@Api(tags = "文章收藏模块")
public class MarkArticleController extends BaseController{


    @Resource
    private IMarkArticleService markArticleService;
    /**
     * 查所有
     */
    @GetMapping
    @ApiOperation("查所有")
    public Result queryAll(){
        List<MarkArticle> list = markArticleService.list();
        return toDataResult(list);
    }
    /**
     * 根据id查询
     */
    @GetMapping("/{id}")
    public Result queryById(@PathVariable Long id){
        MarkArticle MarkArticle = markArticleService.getById(id);
        return toDataResult(MarkArticle);
    }

    /**
     * 增加
     */
    @PostMapping
    @ApiOperation("增加一条")
    public Result add(@RequestBody MarkArticle markArticle){
        boolean save = markArticleService.save(markArticle);
        return toResult(save);
    }
    /**
     * 编辑
     */
    @PutMapping
    @ApiOperation("编辑一条")
    public Result edit(@RequestBody MarkArticle markArticle){
        boolean result = markArticleService.updateById(markArticle);
        return toResult(result);
    }
    /**
     * 根据id删除
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除")
    public Result removeById(@PathVariable Long id){
        boolean result = markArticleService.removeById(id);
        return toResult(result);
    }
}
